package com.example.peanutsubway.web;

import com.alibaba.fastjson.JSONObject;
import com.example.peanutsubway.annotation.ResponseTypeAnnotation;
import com.example.peanutsubway.entity.Channel;
import com.example.peanutsubway.entity.PageInfo;
import com.example.peanutsubway.service.impl.ChannelServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author：liyangsong
 * @Version：1.0
 * @Date：2021/10/15-11:07
 * @Since:jdk1.8
 * @Description:
 */


@WebServlet("/channel.do")
public class ChannelServlet extends BaseServlet<Channel> {
    private ChannelServiceImpl channelService = new ChannelServiceImpl();

    @ResponseTypeAnnotation
    public String showAllChannel(Channel channel) {
        String nowPage = request.getParameter("nowPage");
        String pageSize = request.getParameter("pageSize");
        PageInfo pageInfo = channelService.showAllChannel(channel, pageSize, nowPage);
        String jsonString = JSONObject.toJSONString(pageInfo);
        return jsonString;
    }

    /**
     * 添加渠道
     * @param channel
     * @return
     */
    @ResponseTypeAnnotation
    public String addChannel(Channel channel) {
        Boolean aBoolean = channelService.addChannel(channel);
        String message =aBoolean?"添加成功":"添加失败";
        return message;
    }

    /**
     * 添加
     * @param channel
     * @return
     */
    public String addAdress(Channel channel){
        Boolean aBoolean = channelService.addAdress(channel.getDownloadAdress(), channel.getId());
        String message = aBoolean?"添加地址成功":"添加地址失败";
        return message;
    }
    public String deteleChannel(Channel channel){
        Boolean aBoolean = channelService.deteleAdress(channel.getId());
        String message = aBoolean?"删除成功":"删除失败";
        return message;
    }
}
